package com.demo.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description swagger配置类
 * @Author Dang Xianyue
 * @Date 2020-08-09 23:13
 * @Version 1.0
 */
@Configuration
@EnableSwagger2//通过@EnableSwagger2注解来启用Swagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {


    //swagger2的配置文件，这里可以配置swagger2的一些基本的内容，比如扫描的包等等
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //为当前包路径
                .apis(RequestHandlerSelectors.basePackage("com.demo"))
                .paths(PathSelectors.any())
                .build();
    }


    //构建 api文档的详细信息函数,注意这里的注解引用的是哪个
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //标题
                .title("swagger-bootstrap-ui RESTful APIs")
                //详情
                .description("swagger-bootstrap-ui")
                //访问地址
                .termsOfServiceUrl("http://localhost:8080/doc.html")
                //版本
                .version("1.0")
                .build();
    }
}
